package hlhj.com.carviewpad.http

import android.content.Context
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import hlhj.com.carviewpad.javabean.FilesBean
import hlhj.com.carviewpad.javabean.GameBean
import hlhj.com.carviewpad.javabean.IdBean
import hlhj.com.carviewpad.javabean.MyBaseBean
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers

/**
 * Created by Never Fear   on 2019\1\15 0015.
Never More....
 */
object Apis {
    fun getFiles(): Observable<Response<FilesBean>>? {
      return  OkGo.get<FilesBean>(Urls.fileslist)
                .converter(object : MyJsonConvert<FilesBean>(){})
                .adapt(ObservableResponse<FilesBean>())
                .subscribeOn(Schedulers.io())
    }

    //获取ID
    fun getIds(device_sn:String): Observable<Response<IdBean>>? {
       return OkGo.get<IdBean>(Urls.getId)
                .params("device_sn",device_sn)
                .converter(object : MyJsonConvert<IdBean>(){})
                .adapt(ObservableResponse<IdBean>())
                .subscribeOn(Schedulers.io())
    }

    //上传记录
    fun upload(record:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.upload)
                .params("record",record)
                .converter(object : MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取公告
    fun getNotice(c:Context): Observable<Response<MyBaseBean>>? {
       return OkGo.get<MyBaseBean>(Urls.notice)
                .converter(object : MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //是否有更新
    fun getIsupdata(c:Context): Observable<Response<MyBaseBean>>? {
       return OkGo.get<MyBaseBean>(Urls.isUpdata)
                .converter(object : MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取游戏信息
    fun getGame(): Observable<Response<GameBean>>? {
       return OkGo.get<GameBean>(Urls.gameInfo)
                .converter(object : MyJsonConvert<GameBean>(){})
                .adapt(ObservableResponse<GameBean>())
                .subscribeOn(Schedulers.io())
    }
}